﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Corina.Common
{
    public class RegexHelper
    {
        public static string[] GetUpperChar(string content)
        {
            string pattern = @"[A-Z]";
            return Regex.Matches(content, pattern).OfType<Match>().Select(t => t.Value).ToArray();
        }

        public static bool MatchIPAddress(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return false;
            }
            string pattern = @"\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b";
            return Regex.IsMatch(content, pattern);
        }

        public static string ExtractIPAddress(string content)
        {
            string pattern = @"\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b";
            return Regex.Match(content, pattern).Value;
        }

        public static bool MatchMobile(string content)
        {
            if (string.IsNullOrEmpty(content))
            {
                return false;
            }
            string pattern = @"^(13[0-9]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9]|147)\d{8}$";

            return Regex.IsMatch(content, pattern);
        }

        public static string MatchRGBCode(string content)
        {
            string pattern = @"[0-9]{9}=>";
            return Regex.Match(content, pattern).Value.Replace("=>", "");
        }

        public static List<string> MatchMeasure(string content)
        {
            string pattern = @"第(.*?);";
            return Regex.Matches(content, pattern).OfType<Match>().Select(t => t.Value).ToList();
        }
    }
}
